<?php

namespace app\api\controller;

use think\Controller;
use app\data\Data;

class Person extends Index
{
    public function index()
    {
        $userinfo = cookie('username');
        $user = base64_decode($userinfo);
        $id = explode(',', $user);
        if (!isset($id[1])) {
            $this->_jsonp('1000', '您还未登录', null);
        }
        $where['uid'] = $id[1];
        $join[0] = '__ROLE__ r';
        $join[1] = 'r.id = u.r_id';
        $alias = 'u';
        $field = 'u.username,u.email,u.sex,u.phone,u.describe,r.name';
        $zgh_user = new Data('user');
        $res = $zgh_user->joinOne($join, $where, $field, $alias);
        if ($res) {
            $this->_jsonp('200', '好的', $res);
        } else {
            $this->_jsonp('1000', '不好', null);
        }
    }

    public function update()
    {
        $data['username'] = input('get.username');
        $data['sex'] = input('get.sex');
        $data['phone'] = input('get.phone');
        $data['email'] = input('get.email');
        $data['describe'] = input('get.desc');


        $userinfo = cookie('username');
        $user = base64_decode($userinfo);
        $id = explode(',', $user);
        if (!isset($id[1])) {
            $this->_jsonp('1000', '您还未登录', null);
        }
        $where['uid'] = $id[1];

        //dump($data);exit;
        $zgh_user = new Data('user');
        $res = $zgh_user->_update($data, $where);
        if ($res !== false) {
            session('username', null);
            action_log('编辑个人信息', 'log_admin', 1);
            $this->_jsonp('200', '编辑成功', $res);
        } else {
            action_log('编辑个人信息', 'log_admin');
            $this->_jsonp('1000', '编辑失败', null);
        }

    }
}